package edu.hunau.cxb19.oop.class11;

import java.util.Random;

import org.junit.Test;

import edu.hunau.cxb19.oop.class11.hk.Player;
import edu.hunau.cxb19.oop.class11.hk.Poker;

/**
 *
 * @author hb
 *
 *         2020-03-03 14:47:08
 */
public class PokerTest {

	public Poker[] initNewPorks() {
		Poker[] pokers = new Poker[54];
		int index = 0;
		// 52张扑克牌
		for (int suit = 0; suit <= Poker.SUIT_FANGKU; suit++) {
			for (int rank = 0; rank <= Poker.RANK_2; rank++) {
				pokers[index++] = new Poker(suit, rank);
			}
		}

		pokers[index++] = new Poker(Poker.SUIT_KING, Poker.SMALL);
		pokers[index++] = new Poker(Poker.SUIT_KING, Poker.BIG);

		return pokers;

	}

	public void print(Poker[] pokers) {
		for (int i = 0; i < pokers.length; i++) {
			System.out.print(pokers[i] + " ");
			if ((i + 1) % 13 == 0) {
				System.out.println();
			}

		}

	}

	/**
	 * 洗牌
	 * 
	 * @param pokers
	 */
	public void suffer(Poker[] pokers) {
		Random r = new Random();
		for (int i = pokers.length - 1; i > 0; i--) {
			int index = r.nextInt(i);// 获得一个随机下标[0,i-1]
			// 将下标i和index的数据进行交换
			Poker temp = pokers[i];
			pokers[i] = pokers[index];
			pokers[index] = temp;
		}

	}

	@Test
	public void testPoker() {
		Poker[] newPokers = initNewPorks();
		print(newPokers);
		System.out.println("\n-------洗牌--------");
		suffer(newPokers);
		print(newPokers);

		// 实例化三个玩家
		Player p1 = new Player("张飞");
		Player p2 = new Player("貂蝉");
		Player p3 = new Player("李逵");

		Player[] players = { p1, p2, p3 };
		// 斗地主，需要预留3张底牌
		for (int i = 0; i < newPokers.length - 3; i++) {
			players[i % 3].add(newPokers[i]);
		}
		System.out.println();
		for (int i = 0; i < players.length; i++) {
			System.out.println(players[i]);
		}
	}

	@Test
	public void test() {
		Random r = new Random();
		for (int i = 0; i < 10; i++) {
			System.out.print(r.nextInt(100) + " ");
		}
	}
}
